﻿Public Class fSedes
    Dim daSedes As lbGlobalcom.dsGlobalTableAdapters.GLO_SEDESTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub GLO_SEDESBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_SEDESBindingNavigatorSaveItem.Click
        Try
            Validate()
            GLO_SEDESBindingSource.EndEdit()
            daSedes.Update(DsGlobal.GLO_SEDES)
            MessageBox.Show("Se salvarón registros con exito", "Salva Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub LLenaCiudades()
        Try
            Dim daCiudad As New lbGlobalcom.dsGlobalTableAdapters.GLO_MUNICIPIOSTableAdapter
            daCiudad.Fill(Me.DsGlobal.GLO_MUNICIPIOS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub


    Private Sub btnCargarSedes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargarSedes.Click
        Try
            If Me.DsGlobal.GLO_SEDES.GetChanges() IsNot Nothing Then
                GLO_SEDESBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_SEDESBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daSedes.Fill(DsGlobal.GLO_SEDES)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fSedes_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsGlobal.GLO_SEDES.GetChanges() IsNot Nothing Then
                GLO_SEDESBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_SEDESBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fSedes_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        daSedes = New lbGlobalcom.dsGlobalTableAdapters.GLO_SEDESTableAdapter
        daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        LLenaCiudades()
    End Sub

    Private Sub GLO_SEDESDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles GLO_SEDESDataGridView.CellBeginEdit
        If e.ColumnIndex = 1 AndAlso GLO_SEDESDataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
            dt = daClave.GetDataByIdClavePrimaria("GLO_SEDES")
            If dt.Count Then
                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                dr = dt.Rows(0)
                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                GLO_SEDESDataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                Cons = Nothing
                GLO_SEDESBindingSource.EndEdit()
                daSedes.Update(DsGlobal.GLO_SEDES)
            End If
        End If
    End Sub

    Private Sub GLO_SEDESDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles GLO_SEDESDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    'Private Sub GLO_SEDESDataGridView_RowsRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles GLO_SEDESDataGridView.RowsRemoved
    '    MessageBox.Show("Registro borrado con exito", "Elimina regsitro", MessageBoxButtons.OK, MessageBoxIcon.Information)
    'End Sub



    Private Sub GLO_SEDESDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles GLO_SEDESDataGridView.UserDeletedRow
        Try
            daSedes.Update(DsGlobal.GLO_SEDES)
            MessageBox.Show("Registro borrado con exito", "Elimina regsitro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub



    Private Sub GLO_SEDESDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles GLO_SEDESDataGridView.UserDeletingRow
        If MessageBox.Show("Desea borrar el registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

        If MessageBox.Show("Desea borrar el registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            GLO_SEDESBindingSource.Remove(GLO_SEDESBindingSource.Current)
            GLO_SEDESBindingNavigatorSaveItem.PerformClick()
        End If

    End Sub

 
End Class